<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //连接两个数组
        let arr1 = [1,2,3,4];
        let arr2 = [5,6,7,8,9];
        let arr3 = arr1.concat(arr2);//传统api
        let arr4 = [...arr1,...arr2];//展开运算符
        console.log(arr3,arr4);

        //在函数里使用
        function sum(...numbers) {
            return numbers.reduce((preValue,currentValue)=>{
                return preValue+currentValue;
            })
        }
        console.log(sum(1,2,3,4,5));

        //构造对象字面量的时候使用展开语法
        let person = {name:'tom',age:18}
        let person2 = {...person};
        //console.log(...person);//报错，不能展开对象
        person.name = 'jerry';
        console.log('person',person);
        console.log('person2',person2);

        let person3 = {...person,name:'jack',address:'大陈'}//可以直接更改（合并）属性
        console.log('person3',person3);
  

    </script>
</body>
</html>